import { createRouter, createWebHistory } from 'vue-router'
import Home from "@/views/Home.vue";
import Login from "@/views/Login.vue";
import SignUp from "@/views/SignUp.vue";
import CoursePage  from "@/components/Course/CoursePage.vue";
import CourseDetail from '@/components/Course/CourseDetail.vue';
import TeacherCoursePage  from "@/components/Course/TeacherCoursePage.vue";
import TeacherCourseDetail  from "@/components/Course/TeacherCourseDetail.vue";
import TeacherPostDetail from '@/components/Post/TeacherPostDetail.vue';
import PostDetail from '@/components/Post/PostDetail.vue';
import NoticeDetail from '../components/Notice/NoticeDetail.vue';
import NoticePage from "@/components/Notice/NoticePage.vue";
import AssignmentDetail from "@/components/Assignments/AssignmentDetail.vue";
import SubmitAssignment from "@/components/Assignments/SubmitAssignment.vue";
import MarkAssignment from "@/components/Assignments/MarkAssignment.vue";
import PublishNoticePage from "@/components/Notice/PubilshNoticePage.vue";
import ProfilePage from "@/components/Profile/ProfilePage.vue";
import setExam from "@/components/Exam/SetExam.vue";
import ReviewAssignment from "@/components/Assignments/ReviewAssignment.vue";
import AIDialoguePage from "@/components/AI/AIDialoguePage.vue";
import SubmitExam from "@/components/Exam/SubmitExam.vue";
import SubmitAnswer from "@/components/Exam/SubmitAnswer.vue";
import SubmitStudentAnswer from "@/components/Exam/SubmitStudentAnswer.vue";
import PublishHomework from "@/components/Assignments/PublishHomework.vue";
const routes = [
  {
    path:'/',
    name:'home',
    component:Home,
    redirect: '/login',
  },
  {
    path:'/login',
    name:'login',
    component:Login,
  },
  {
    path:'/signUp',
    name:'signup',
    component:SignUp,
  },
    {
        path:'/coursePage',
        name:'coursepage',
        component:CoursePage,
    },
    {
        path: '/course/:course_id',
        name: 'courseDetail',
        component: CourseDetail, // 引用课程详情组件
        props: route => ({ course_id: route.params.course_id }), // 通过props接收参数
    },
    {
        path: '/teachercoursepage',
        name: 'TeacherCoursePage',
        component: TeacherCoursePage, // 引用课程详情组件
    },
    {
        path: '/Teachercourse/:course_id',
        name: 'TeacherCourseDetail',
        component: TeacherCourseDetail, // 引用课程详情组件
        props: route => ({ course_id: route.params.course_id }), // 通过props接收参数
    },
    {
        path: '/postdetail/:id',
        name: 'PostDetail',
        component: PostDetail
    },
    {
        path: '/TeacherPostDetail/:id',
        name: 'TeacherPostDetail',
        component: TeacherPostDetail,
    },
    {
        path: '/noticePage',  //
        name: 'NoticePage',
        component: NoticePage,
    },
    {
        path: '/notice/:id',
        name: 'NoticeDetail',
        component: NoticeDetail,
    },
    {
        path: '/publishNoticePage',
        name: 'PublishNoticePage',
        component:PublishNoticePage,
    },
    {
        path: '/assignment/:homework_id',
        name: 'AssignmentDetail',
        component: AssignmentDetail, // 这里使用实际的组件引用
        props: true
    },
    {
        path: '/markAssignment/:homework_id',
        name: 'MarkAssignment',
        component: MarkAssignment, // 这里使用实际的组件引用
        props: true
    },
    {
        path: '/assignmentSubmit',
        name: 'AssignmentSubmit',
        component: SubmitAssignment,
        props: (route) => ({
            homework_id: route.query.homework_id,
            title: route.query.title,
            content: route.query.content,
        }),
    },
    {
        path: '/setExam',
        name: 'SetExam',
        component: setExam,
        props: (route) => ({
            course_id: route.query.course_id,
        }),
    },
    {
        path: '/profile',
        name: 'ProfilePage',
        component: ProfilePage,
        props: (route) => ({
            user_id: route.query.user_id,
            profileuser_id: route.query.profileuser_id,
        }),
    },
    {// 作业互评
        path:'/reviewAssignment',
        name: 'ReviewAssignment',
        component: ReviewAssignment,
        props: (route) => ({
            course_id: route.query.course_id,
            homework_id: route.query.homework_id,
        }),
    },
    {
        path: "/publishhomework",
        name: "PublishHomework",
        component: PublishHomework,
        props: (route) => ({
            course_id: route.query.course_id, // 从路由参数中提取 course_id
        }),
    },
    {// AI对话
        path:'/AIDialogue',
        name: 'AIDialogue',
        component: AIDialoguePage,
        props: true
    },
    {
        path: '/submitexam',
        name: 'SubmitExam',
        component: SubmitExam,
    },
    {
        path: '/submitstudentanswer',
        name: 'SubmitStudentAnswer',
        component: SubmitStudentAnswer,
        props: route => ({ exam_id: route.query.exam_id, course_id: route.query.course_id })  // Pass exam_id as a prop to the component
    },

    {
        path: '/submitanswer',
        name: 'SubmitAnswer',
        component: SubmitAnswer,
        props: (route) => ({
            exam_id: route.query.exam_id,
        }),
    }
]

/*//挂载路由导航守卫
//to是我们跳转的路径，from是来自的路径，next为放行函数
router.beforeEach((to,from,next)=>{
  //如果用户访问登录页，直接放行
  if(to.path ==="/login") return next();
  //从sessionStorage中获取到保存的token值
  const tokenStr = window.sessionStorage.getItem("token");
  //没有token，强制跳转到登录页面
  if(!tokenStr) return next("/login");
  next();//有token，直接放行
})*/
const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

export default router
